import { defineStore } from 'pinia'

/* 个人中心 */
export default defineStore('storeStore', {
	state(){
		return {
			id: 0, 
			name:'', 
			sn: '',
			type: 0,
			doorhead: '',
			exam: 0, 
			state: 0,
			address: '',
			lng: 0,
			lat: 0,
			dist_id: 0,
			city_id: 0,
			timsig: '',
			cart: [] as {number: number}[], // 商品
			todo: { buy_order:0, buy_refund:0, remit:0, sell_order:0, sell_refund:0, storage_receive: 0, storage_send: 0, matter: 0, item:0, msg: 0},
			stat: { today: 0, item: 0, flux: 0, expand: 0},
			msgs: [],
			convs: []
		}
	},
	getters: {
		cartCount(){
			let count = 0
			this.cart.map((r: {number: number})=>{
				count += r.number
			})
			return count
		}
	},
	actions: {
		update(values: object) {
			Object.assign(this, values)
		},
		updateCart(item: {id: number, number: number}){
			if(!this.cart.some((r: {id: number}, i: number) => r.id==item.id && (this.cart[i].number = item.number))){
				this.cart.push(item)
			}
		}
	}
})